
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for view_group_photos.
	''' </summary>
	Public Partial Class view_group_photos
		Inherits BaseWebPage
		Protected grpID As Integer = -1
		Protected htPageConstants As New Hashtable()

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			' this.pageTemplate.PageTitle = PageTitles.VIEW_GROUP_PHOTOS_PAGE;

			Dim usr As User = LoggedUser

			If usr = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			If Request.Params(Constants.GROUP_PARAM) = Nothing OrElse Request.Params(Constants.GROUP_PARAM) = "" Then
				Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
			End If

			Me.initPageTitles(Constants.VIEW_GROUP_PHOTOS, "", uploadImageForm, Nothing, htPageConstants)
			Me.initAdvertisements(uploadImageForm, Nothing)

			If Constants.SHOW_GROUPS <> Constants.SHOW_ON Then
				Throw New Exception(Constants.ERROR_MESSAGE_NO_ACCESS)
			End If

			Try
				grpID = Convert.ToInt32(Request.Params(Constants.GROUP_PARAM))
			Catch
				Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
			End Try

			If Not IsPostBack Then
				BindList()
			End If
		End Sub

		Public Function CreateDataSource() As ICollection
			Dim grp As BO.Group = Groups.GetGroupByID(grpID)

			If grp <> Nothing Then
				Dim pics As ArrayList = grp.GetPictures()
				Dim picsCount As Integer = pics.Count
				If picsCount = 0 Then
					lblNoImage.Visible = True
				Else
					lblNoImage.Visible = False
				End If

				Dim dt As New DataTable()
				Dim dr As DataRow

				dt.Columns.Add(New DataColumn("ImageURL", GetType(String)))
				dt.Columns.Add(New DataColumn("ImageID", GetType(String)))
				dt.Columns.Add(New DataColumn("Description", GetType(String)))
				dt.Columns.Add(New DataColumn("Comments", GetType(String)))
				dt.Columns.Add(New DataColumn("FoolName", GetType(String)))
				Dim i As Integer = 0
				While i < picsCount
					dr = dt.NewRow()

					Dim temp As GroupPicture = DirectCast(pics(i), GroupPicture)
					dr(0) = Pictures.GetPictureSrcFullURL(temp, True, "../")
					dr(1) = temp.ID.ToString()
					If temp.Desc = "" Then
						dr(2) = "&nbsp;"
					Else
						dr(2) = temp.Desc
					End If
					dr(3) = temp.Comments.Count + " Comment"
					If temp.Comments.Count <> 1 Then
						dr(3) = dr(3) + "s"
					End If
					dr(4) = grp.Name
					dt.Rows.Add(dr)
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While

				Dim dv As New DataView(dt)

				hlBackToGroup.NavigateUrl = "../" + Constants.GROUP_WELCOME + "?" + Constants.GROUP_PARAM + "=" + grpID
				hlBackToGroup.Text = (Me.GetPageConstText(htPageConstants, "CONST_GroupBackLink_TEXT")).Replace("[PARAM]", grp.Name)

				Return dv
			End If
			Return Nothing
		End Function

		Public Sub BindList()
			dlPictures.DataSource = CreateDataSource()
			dlPictures.DataBind()
		End Sub

		Public Sub dlPictures_ItemCommand(ByVal Sender As Object, ByVal e As DataListCommandEventArgs)
			Dim src As Object = e.CommandSource
			Dim cmd As String = ""
			Dim usr As BO.User = Me.LoggedUser
			Dim grp As BO.Group = Groups.GetGroupByID(grpID)

			Dim type As String = src.[GetType]().ToString()
			Select Case type
				Case "System.Web.UI.WebControls.ImageButton"
					cmd = (DirectCast(src, ImageButton)).CommandName
					Exit Select
				Case "System.Web.UI.WebControls.LinkButton"
					cmd = (DirectCast(src, LinkButton)).CommandName
					Exit Select
				Case "System.Web.UI.WebControls.Button"
					cmd = (DirectCast(src, Button)).CommandName
					Exit Select
			End Select
			Select Case cmd
				Case "ViewLargerPhotoLink"
					Response.Redirect(Constants.VIEW_PHOTO_ALBUM_COMMENTS_PAGE + "?img=" + e.CommandArgument.ToString() + "&usr=" + usr.ID + "&" + Constants.GROUP_PARAM + "=" + grp.ID)
					Exit Select
				Case "PostComment"
					Response.Redirect(Constants.ADD_PHOTO_ALBUM_COMMENTS + "?img=" + e.CommandArgument.ToString() + "&usr=" + usr.ID + "&" + Constants.GROUP_PARAM + "=" + grp.ID)
					Exit Select
			End Select
			BindList()
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.dlPictures.ItemCommand, AddressOf Me.dlPictures_ItemCommand
		End Sub
#End Region

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable uploadImageForm.
		====================
		Public ReadOnly Property uploadImageForm() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_uploadImageForm
			End Get
		End Property
		'set { Migrated_uploadImageForm = value; }
	End Class
End Namespace






